package com.hoshiicloud.common.generator.id.controller;

import com.hoshiicloud.common.generator.id.service.UidGenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags = "获取ID接口")
public class UidRestController {

    @Autowired
    private UidGenService uidGenService;

    @RequestMapping(value = "/getuuId", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "获取一个ID")
    public String getuuId() {
        return String.valueOf(uidGenService.getUid());
    }

    @RequestMapping(value = "/getuuIdSet", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "获取多个ID")
    @ApiImplicitParam(name = "count", value = "要获取的ID数量", example = "10")
    public Set<String> getuuIdSet(@RequestParam int count) {
        int idNum = 100;
        // 限制单次获取的数量
        if (count > idNum) {
            log.error("单次获取id的个数不能超过100");
            return null;
        }
        return uidGenService.getUidList(count);
    }

	/**
	 * 租户会员编码（10位随机数字，同一租户内唯一）
	 * @return String
	 */
	@RequestMapping(value = "/getComUserCode", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "获取一个ID")
    public String getComUserCode() {
        return String.valueOf(uidGenService.getComUserCode());
    }

	/**
	 * 平台消费者用户编码和邀请码（7的随机数，同一平台内唯一）
	 * @return
	 */
	@RequestMapping(value = "/getPlatCousomerCode", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "获取一个ID")
    public String getPlatCousomerCode() {
        return String.valueOf(uidGenService.getInviteCode());
    }

}
